import { rawRequestClient } from '#/api/request';

// 模型配置接口类型定义
export interface ModelConfig {
  id?: number;
  model_id?: number;
  key: string;
  value: string;
  type: string;
  is_enabled: boolean;
  created_at?: string;
  created_by?: string;
}

// 渠道信息接口类型定义
export interface ChannelInfo {
  id?: number;
  name: string;
  type: string;
  base_url: string;
  accounts?: any[];
  configs?: any[];
  created_at?: string;
  created_by?: string;
  updated_at?: string;
  updated_by?: string;
}

// 模型接口类型定义
export interface Model {
  id?: number;
  name: string;
  description?: string;
  channel_id: number;
  status?: number;
  is_active?: boolean;
  configs?: ModelConfig[];
  channel?: ChannelInfo;
  created_at?: string;
  created_by?: string;
  updated_at?: string;
  updated_by?: string;
}

// 获取模型列表
export function getModelList(params: {
  page?: number;
  size?: number;
  name?: string;
  status?: number;
  channel_id?: number;
  is_active?: boolean;
}) {
  return rawRequestClient.get(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models`, { params });
}

// 创建模型
export function createModel(data: Model) {
  return rawRequestClient.post(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models`, data);
}

// 获取单个模型详情
export function getModelDetail(id: number) {
  return rawRequestClient.get(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models/${id}`);
}

// 更新模型
export function updateModel(id: number, data: Model) {
  return rawRequestClient.put(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models/${id}`, data);
}

// 删除模型
export function deleteModel(id: number) {
  return rawRequestClient.delete(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models/${id}`);
}

// 添加模型配置
export function addModelConfig(id: number, config: ModelConfig) {
  return rawRequestClient.post(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models/${id}/configs`, config);
}

// 删除模型配置
export function deleteModelConfigs(ids: number[]) {
  return rawRequestClient.delete(`${import.meta.env.VITE_MODEL_LAKE_SERVER}/management/models/configs`, { params: { ids } });
}
